package com.study.shengsiyuan.example06;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.protobuf.ProtobufDecoder;
import io.netty.handler.codec.protobuf.ProtobufEncoder;
import io.netty.handler.codec.protobuf.ProtobufVarint32FrameDecoder;
import io.netty.handler.codec.protobuf.ProtobufVarint32LengthFieldPrepender;

public class MyProtobufClientInitializer extends ChannelInitializer<SocketChannel> {

	@Override
	protected void initChannel(SocketChannel ch) throws Exception {
		ChannelPipeline pl = ch.pipeline(); //连接所有处理器
		pl	//netty 提供了 4个 protobuf 处理器
			.addLast(new ProtobufVarint32FrameDecoder())
			.addLast(new ProtobufDecoder(MyDataInfo.MyMessage.getDefaultInstance()))//参数是我们定义的信息类型
			.addLast(new ProtobufVarint32LengthFieldPrepender())
			.addLast(new ProtobufEncoder())
			.addLast(new MyProtobufClientHandler());
	}

}
